
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Nginx 的限制请求速率和连接数的功能是如何实现的？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Nginx 的限制请求速率和连接数的功能是如何实现的？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Nginx中用于控制流量和保护服务器资源的两个主要模块是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Nginx中用于限制请求速率和连接数的主要模块是 `limit_req` 模块和 `limit_conn` 模块。</div>
          </div>
          <div class="card-source">来源: 文档开篇段落</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Nginx的请求速率限制功能（Rate Limiting）主要用于解决什么问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">限制请求速率的功能可以用来控制每个客户端在单位时间内发送的请求数量。这通常用于防止DDoS攻击或资源滥用。</div>
          </div>
          <div class="card-source">来源: 1. 限制请求速率（Rate Limiting）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在Nginx中，如何使用`limit_req_zone`指令定义一个请求速率限制区域？请解释其关键参数。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过 `limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s;` 语法进行定义。其中`$binary_remote_addr`是客户端IP地址的二进制表示，`zone=mylimit:10m`定义了区域名称和内存大小，`rate=1r/s`指定了每秒允许的请求数量。</div>
          </div>
          <div class="card-source">来源: 1.1. limit_req 模块 - 配置步骤</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在`limit_req`指令中，`burst`和`nodelay`参数分别代表什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`burst`参数表示允许的突发请求数，即在限制速率之外的额外请求数量。`nodelay`参数表示不延迟处理这些突发请求。</div>
          </div>
          <div class="card-source">来源: 1.1. limit_req 模块 - 配置步骤</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Nginx的连接数限制功能（Connection Limiting）有什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">限制连接数的功能用于控制每个客户端与服务器建立的连接数量。这有助于避免某些客户端占用过多连接资源，从而影响其他客户端的正常访问。</div>
          </div>
          <div class="card-source">来源: 2. 限制连接数（Connection Limiting）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">请说明如何配置Nginx，以实现限制每个IP地址最多只能建立5个并发连接。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">首先在 http 块中定义连接限制区域：`limit_conn_zone $binary_remote_addr zone=addr:10m;`。然后，在 server 或 location 块中应用此限制：`limit_conn addr 5;`。</div>
          </div>
          <div class="card-source">来源: 2.2. 限制连接数示例</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
